<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="检查时间" style="width: 308px">
        <el-date-picker v-model="daterangeSendTime" value-format="YYYY-MM-DD" type="daterange" range-separator="-" start-placeholder="开始日期"
          end-placeholder="结束日期"></el-date-picker>
      </el-form-item>

      <el-form-item label="收费站" prop="deptId">
        <el-tree-select v-model="queryParams.deptId" :data="deptOptions" :props="{ value: 'id', label: 'label', children: 'children' }" value-key="id"
          class="margin-right" placeholder="请选择部门" check-strictly clearable @change="bindChangeTree($event,'deptId')" />

      </el-form-item>

      <el-form-item label="检查类型" prop="type">
        <el-select v-model="queryParams.type" >
          <el-option v-for="dict in check_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>

      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button plain icon="plus"  v-hasPermi="['coordination:improvement:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['coordination:improvement:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="improvementList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="检查类型" align="center" prop="checkType" />
      <el-table-column label="项目" align="center" prop="checkType" />
      <el-table-column label="检查内容" align="center" prop="deptId" />
      <el-table-column label="通过/不通过" align="center" prop="checkDate" width="180">
      </el-table-column>

      <el-table-column label="不通过原因" align="center" prop="sourceDeptId" />
    </el-table>

    <pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改整改信息对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="improvementRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="部门id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门id" />
        </el-form-item>
        <el-form-item label="检查时间" prop="checkDate">
          <el-date-picker clearable v-model="form.checkDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择检查时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="部门id" prop="sourceDeptId">
          <el-input v-model="form.sourceDeptId" placeholder="请输入部门id" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Improvement">
import { listImprovement, getImprovement, delImprovement, addImprovement, updateImprovement } from "@/api/coordination/improvement";

const { proxy } = getCurrentInstance();
const { check_type,check_category } = proxy.useDict('check_type','check_category');


const improvementList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    deptId: null,
    checkDate: null,
    checkType: null,
    sourceDeptId: null,
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询整改信息列表 */
function getList() {
  loading.value = true;
  listImprovement(queryParams.value).then(response => {
    improvementList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    deptId: null,
    checkDate: null,
    checkType: null,
    sourceDeptId: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    remark: null
  };
  proxy.resetForm("improvementRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}



/** 导出按钮操作 */
function handleExport() {
  proxy.download('coordination/improvement/export', {
    ...queryParams.value
  }, `提升整改_${new Date().getTime()}.xlsx`)
}

getList();
</script>
